package com.ourteam.product.requirement.api;

import com.ourteam.frame.web.AbstractTreeNodeBuilder;
import com.ourteam.product.requirement.domain.ProductDefineBean;
import com.ourteam.product.requirement.service.IProductService;
import com.ourteam.product.requirement.service.ProductServiceFactory;

public class ProductDefineItemsSubNodeBuilder
		extends AbstractTreeNodeBuilder<ProductDefineBean, ProductDefineItemBean> {

	private static final IProductService PRODUCT_SERVICE = ProductServiceFactory.getProductService();
	
	@Override
	public ProductDefineItemBean[] getTreeNodeObjects(ProductDefineBean parentObject) throws Exception {

		ProductDefineItemBean[] itemBeans = new ProductDefineItemBean[] {
				new ProductDefineItemBean(parentObject.getId(), "productGlossaryList"),
				new ProductDefineItemBean(parentObject.getId(), "productFeatureList"),
				new ProductDefineItemBean(parentObject.getId(), "productRequiremnetList") };

		return itemBeans;
	}

	@Override
	public Object getNodeId(ProductDefineItemBean childObject) throws Exception {
		return childObject.getProductDefineId();
	}

	@Override
	public boolean isLeaf(ProductDefineItemBean childObject) throws Exception {
		return true;
	}

	@Override
	public int getChildCount(ProductDefineItemBean childObject) throws Exception {

		return 0;
	}

	@Override
	public String getNodeDefineId(ProductDefineItemBean childObject) throws Exception {
		return childObject.getProductDefineItemType();
	}

	@Override
	public ProductDefineBean converToParentObject(Object parent) throws Exception {
		return PRODUCT_SERVICE.getProductDefineById(Long.parseLong(parent.toString()));
	}

}
